﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

// Site.cs
// The representation of an Area in the Overworld; when the player walks into this
// on the Overworld they enter the corresponding Area.
namespace RTS_RPG
{
    public class Site
    {
        // Site's Fields
        public String name;
        public Texture2D avatar;
        public Area link;
        public Vector2 location;

        // Constructor
        public Site(String nm, Texture2D avt, Area lnk, Vector2 loc)
        {
            name = nm;
            avatar = avt;
            link = lnk;
            location = loc;
        }

        // either world or area are used (whichever this site is in), the other should be null
        public Boolean check_entry(Overworld world, Area area)
        {
            if (world != null)
            {
                if (Vector2.Distance(world.player_location, location) < avatar.Width / 2 + 6)
                {
                    world.player_location.X = location.X;
                    world.player_location.Y = location.Y + (avatar.Height / 2) + 32;
                    return true;
                }
                return false;
            }

            else if (area != null)
            {
                if (Vector2.Distance(area.player_location, location) < avatar.Width / 2 + 6)
                {
                    area.player_location.X = location.X;
                    area.player_location.Y = location.Y + (avatar.Height / 2) + 32;
                    area.player_direction = (float)(0.5f * Math.PI);
                    return true;
                }
                return false;
            }

            else return false;
        }

        // returns true if the player has left the area associated with this site
        public Boolean update(MouseState mstate, KeyboardState kstate)
        {
            return link.update(mstate, kstate);
        }

        public void draw(SpriteBatch spBatch)
        {
            spBatch.Draw(avatar, new Vector2(location.X - (avatar.Width / 2), location.Y - (avatar.Height / 2)), Color.White);
        }

        public void draw_area(SpriteBatch spBatch, GraphicsDevice graphics_dev)
        {
            link.draw(spBatch, graphics_dev);
        }
    }
}
